package com.gxan.dao.impl;

import com.gxan.dao.StandardDao;
import com.gxan.pojo.SalStandard;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.gxan.utils.db.JdbcUtils;


public class StandardDaoImpl extends JdbcUtils implements StandardDao {

    /**
     * 查询薪酬标准表所有内容
     * @param offset
     * @param rows
     * @return
     * @throws SQLException
     */
    @Override
    public List<SalStandard> queryStandardList(Integer offset, Integer rows) throws SQLException {
        String sql = "SELECT * FROM sal_standard limit ?,?";
        Object[] params = {offset,rows};
        return super.queryListEntity(SalStandard.class,sql,params);
    }
    //薪酬标准表计数查询
    @Override
    public Integer countStandard() throws SQLException {
        String sql = "select count(*) from sal_standard";
        return super.findAllForInt(sql);
    }
    //薪酬标准添加
    @Override
    public int addStandardList(SalStandard salStandard) throws SQLException {
        String sql = "insert  into sal_standard(sal_standard_code,sal_standard_name,total,setter,registrant,register_time,basic_salary,performance,transportation,communication,meal_subsidy,housing,business,overtime_subsidy)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        Object[] params = {salStandard.getSal_standard_code(),salStandard.getSal_standard_name(),salStandard.getTotal(),salStandard.getSetter(),salStandard.getRegistrant(),salStandard.getRegister_time(),salStandard.getBasic_salary(),salStandard.getPerformance(),salStandard.getTransportation(),salStandard.getCommunication(),salStandard.getMeal_subsidy(),salStandard.getHousing(),salStandard.getBusiness(),salStandard.getOvertime_subsidy()};
        return super.executeUpdate(sql,params);
    }
    //修改
    @Override
    public int updateStandard(SalStandard salStandard) throws SQLException {
        String sql = "update sal_standard set sal_standard_name=?,total=?,setter=?,registrant=?,register_time=?,basic_salary=?,performance=?,transportation=?,communication=?,meal_subsidy=?,housing=?,business=?,overtime_subsidy=? where sal_standard_code=?";
        Object[] params = {salStandard.getSal_standard_name(),salStandard.getTotal(),salStandard.getSetter(),salStandard.getRegistrant(),salStandard.getRegister_time(),salStandard.getBasic_salary(),salStandard.getPerformance(),salStandard.getTransportation(),salStandard.getCommunication(),salStandard.getMeal_subsidy(),salStandard.getHousing(),salStandard.getBusiness(),salStandard.getOvertime_subsidy(),salStandard.getSal_standard_code()};
        return super.executeUpdate(sql,params);
    }
    //复核
    @Override
    public int reviewStandard(SalStandard salStandard) throws SQLException {
        String sql = "update sal_standard set sal_standard_name=?,total=?,setter=?,registrant=?,register_time=?,review_comments=?,basic_salary=?,performance=?,transportation=?,communication=?,meal_subsidy=?,housing=?,business=?,overtime_subsidy=? where sal_standard_code=?";
        Object[] params = {salStandard.getSal_standard_name(),salStandard.getTotal(),salStandard.getSetter(),salStandard.getRegistrant(),salStandard.getRegister_time(),salStandard.getReview_comments(),salStandard.getBasic_salary(),salStandard.getPerformance(),salStandard.getTransportation(),salStandard.getCommunication(),salStandard.getMeal_subsidy(),salStandard.getHousing(),salStandard.getBusiness(),salStandard.getOvertime_subsidy(),salStandard.getSal_standard_code()};
        return super.executeUpdate(sql,params);
    }
    //变更
    @Override
    public int changeStandard(SalStandard salStandard) throws SQLException {
        String sql = "update sal_standard set sal_standard_name=?,total=?,setter=?,registrant=?,register_time=?,reason_change=?,basic_salary=?,performance=?,transportation=?,communication=?,meal_subsidy=?,housing=?,business=?,overtime_subsidy=? where sal_standard_code=?";
        Object[] params = {salStandard.getSal_standard_name(),salStandard.getTotal(),salStandard.getSetter(),salStandard.getRegistrant(),salStandard.getRegister_time(),salStandard.getReason_change(),salStandard.getBasic_salary(),salStandard.getPerformance(),salStandard.getTransportation(),salStandard.getCommunication(),salStandard.getMeal_subsidy(),salStandard.getHousing(),salStandard.getBusiness(),salStandard.getOvertime_subsidy(),salStandard.getSal_standard_code()};
        return super.executeUpdate(sql,params);
    }
    //明细
    @Override
    public int detailsStandard(SalStandard salStandard) throws SQLException {
        String sql = "update sal_standard set sal_standard_name=?,total=?,setter=?,registrant=?,register_time=?,basic_salary=?,performance=?,transportation=?,communication=?,meal_subsidy=?,housing=?,business=?,overtime_subsidy=? where sal_standard_code=?";
        Object[] params = {salStandard.getSal_standard_name(),salStandard.getTotal(),salStandard.getSetter(),salStandard.getRegistrant(),salStandard.getRegister_time(),salStandard.getBasic_salary(),salStandard.getPerformance(),salStandard.getTransportation(),salStandard.getCommunication(),salStandard.getMeal_subsidy(),salStandard.getHousing(),salStandard.getBusiness(),salStandard.getOvertime_subsidy(),salStandard.getSal_standard_code()};
        return super.executeUpdate(sql,params);
    }
    //删除
    @Override
    public int deleteStandard(String sal_standard_code) throws SQLException {
        String sql = "delete from sal_standard where sal_standard_code = ? ";
        return super.executeUpdate(sql,sal_standard_code);
    }
    //搜索
    @Override
    public List<SalStandard> searchStandard(Integer offset, Integer rows,String sal_standard_name ,Integer review_status) throws SQLException {
        String sql = "select * from sal_standard where sal_standard_name like concat('%',?,'%')";
        List<Object> params = new ArrayList<>();
        params.add(sal_standard_name);
        if(review_status != null && !"".equals(review_status)) {
            sql = sql + " and review_status = ?";
            params.add(review_status);
        }
        sql = sql + " limit ?,?";
        params.add(offset);
        params.add(rows);
        return super.queryListEntity(SalStandard.class,sql,params.toArray());
    }
    //搜索总条数
    @Override
    public int countSearchStandard(String sal_standard_name,Integer review_status) throws SQLException {
        String sql = "select * from sal_standard where sal_standard_name like concat('%',?,'%')";
        List<Object> params = new ArrayList<>();
        params.add(sal_standard_name);
        if(review_status != null && !"".equals(review_status)) {
            sql = sql + " and review_status = ?";
            params.add(review_status);
        }
        return super.findAllForInt(sql,params.toArray());
    }


}
